package serverletGrade;

import Server.GradeServer;
import Server.StudentServer;
import user.Grade;
import user.Student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "addGradeServlet",urlPatterns = "/addgrade")
public class addGradeServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("UTF-8");
            Grade grade = new Grade();
            grade.setNum(request.getParameter("num"));
            grade.setName(request.getParameter("name"));
            grade.setYear(request.getParameter("year"));
            grade.setTeacher(request.getParameter("teacher"));
            grade.setSlogan(request.getParameter("slogan"));
            grade.setPeopleNum(request.getParameter("peoplenum"));
            System.out.println(grade);
            GradeServer gradeServer = new GradeServer();
            int i = gradeServer.addGradeServer(grade);
            System.out.println("增加"+i+"行");
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/gradeinit");
            requestDispatcher.forward(request,response);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
